package atm05;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MenuPanel extends JPanel implements ActionListener{
    private ATM05 atm05;
    private JButton searchBtn = new JButton(new ImageIcon("src/atm05/Images/buttonFind.jpg"));
    private JButton saveBtn = new JButton(new ImageIcon("src/atm05/Images/buttonSave.jpg"));
    private JButton getBtn = new JButton(new ImageIcon("src/atm05/Images/buttonGet.jpg"));
    private JButton modifyBtn = new JButton(new ImageIcon("src/atm05/Images/buttonModify.jpg"));
    private JButton transferBtn = new JButton("转账");
    private JButton offBtn = new JButton(new ImageIcon("src/atm05/Images/buttonOff.jpg"));
    private Font font = new Font("黑体",Font.BOLD,25);

    public MenuPanel(ATM05 atm05){
        this.atm05 = atm05;
        this.setLayout(null);
        this.setOpaque(false);

        searchBtn.setBounds(0,100,140,50);
        searchBtn.addActionListener(this);

        saveBtn.setBounds(0,240,140,50);
        saveBtn.addActionListener(this);

        getBtn.setBounds(0,380,140,50);
        getBtn.addActionListener(this);

        modifyBtn.setBounds(880,100,140,50);
        modifyBtn.addActionListener(this);

        transferBtn.setBounds(880,240,140,50);
        transferBtn.setFont(font);
        transferBtn.addActionListener(this);

        offBtn.setBounds(880,380,140,50);
        offBtn.addActionListener(this);


        this.add(searchBtn);
        this.add(saveBtn);
        this.add(getBtn);
        this.add(modifyBtn);
        this.add(transferBtn);
        this.add(offBtn);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == searchBtn){
            atm05.getSearchPanel().showBlance();
            atm05.showPanel("search");
        }else if (e.getSource() == saveBtn){
            atm05.showPanel("save");
        }else if (e.getSource() == getBtn){
            atm05.showPanel("get");
        }else if (e.getSource() == transferBtn){
            atm05.showPanel("transfer");
        }else if (e.getSource() == offBtn){
            atm05.showPanel("login");
        }else if (e.getSource() == modifyBtn){
            atm05.showPanel("change");
        }
    }
}
